package com.kimu.order_service_provider.service;

import org.apache.dubbo.config.annotation.DubboService;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.kimu.order_service_interface.entity.Order;
import com.kimu.order_service_interface.mapper.OrderMapper;
import com.kimu.order_service_interface.service.OrderService;

@DubboService
public class OrderServiceImpl implements OrderService {

    private OrderMapper orderMapper;

    public OrderServiceImpl(OrderMapper orderMapper) {
        this.orderMapper = orderMapper;
    }

    @Override
    public int createOrder(Order order) {
        int row = orderMapper.insert(order);
        return row;
    }

    @Override
    public Order getOrderById(Long id) {
        Order order = orderMapper.selectById(id);
        return order;
    }

    @Override
    public int updateOrder(Order order) {
        int row = orderMapper.updateById(order);
        return row;
    }

    @Override
    public int deleteOrderById(Long id) {
        int row = orderMapper.deleteById(id);
        return row;
    }

    @Override
    public IPage<Order> getOrdersByUserId(Page<Order> page, Long userId) {
        IPage<Order> result = orderMapper.getOrdersByUserId(page, userId);
        return result;
    }

}
